<?php
//add upcomming course
add_action('init', 'create_up_comming_course_post_type');
function create_up_comming_course_post_type()
{
    register_post_type('up-comming-course', array(
        'labels' => array(
            'name' => __('Up Comming Courses'),
            'singular_name' => __('Up Comming Course'),
            'add_new' => __('Add New'),
            'add_new_item' => __('Add New Up Comming Courses'),
            'edit' => __('Edit'),
            'edit_item' => __('Edit'),
            'new_item' => __('New'),
            'view' => __('View'),
            'view_item' => __('View this course'),
            'search_items' => __('Search'),
            'not_found' => __('No Events found'),
            'not_found_in_trash' => __('No Events found in Trash')),
        'public' => true,
        'show_ui' => true,
        'publicy_queryable' => true,
        'exclude_from_search' => false,
        'menu_position' => 20,
        'menu_icon' => get_stylesheet_directory_uri() . '/images/calendar.png',
        'hierarchical' => false,
        'query_var' => true,
        'supports' => array(
            'title',
            'editor',
            'comments',
            'author',
            'thumbnail'),
        'rewrite' => array('slug' => 'up-comming-course', 'with_front' => false),
        //'taxonomies' =>  array('post_tag', 'category'),
        'can_export' => true,
        //'register_meta_box_cb'  =>  'call_to_function_do_something',
        'description' => __('Event description here.')));
}

//add header for english course
add_action('add_meta_boxes', 'add_ucc_meta_box');
function add_ucc_meta_box()
{
    add_meta_box('ucc_title_vi', 'Course title (VI)',           'render_ucc_title_vi', 'up-comming-course', 'normal', 'high');
    add_meta_box('ucc_date',     'Up comming course start day', 'render_ucc_date',     'up-comming-course', 'normal', 'high');
}
function render_ucc_title_vi($post){
    $values = get_post_custom($post->ID);
    $text = isset($values['ucc_title_vi']) ? esc_attr($values['ucc_title_vi'][0]) : "";
    wp_nonce_field('my_meta_box_ucc_nonce', 'ucc_nonce');
    echo '<input type="text" name="ucc_title_vi" value="'.$text.'" size="100" />';
}
function render_ucc_date($post)
{
    $values = get_post_custom($post->ID);
    $text = isset($values['ucc_date']) ? esc_attr($values['ucc_date'][0]) : "";
    echo '<input type="text" name="ucc_date" value="'.$text.'" placeholder="Example : 2014/01/20" class="date" size="30" />';
}
add_action('save_post', 'save_ucc');
function save_ucc($post_id)
{
    // Fail if we're doing an auto save
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;

    // if our nonce isn't there, or we can't verify it, bail
    if (!isset($_POST['ucc_nonce']) || !wp_verify_nonce($_POST['ucc_nonce'], 'my_meta_box_ucc_nonce')) return;

    // if our current user can't edit this post, bail
    if (!current_user_can('edit_post'))return;

    // now we can actually save the data
    $allowed = array('a' => array('href' => array()));

    $aPost = array('ucc_title_vi', 'ucc_date');
    foreach ($aPost as $p) {
        if(!isset($_POST[$p])){
            return;
        }
    }
    foreach ($aPost as $p) {
        update_post_meta($post_id, $p, wp_kses($_POST[$p], $allowed));
    }
}
?>